package com.it.arktech.repository.jdbc;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Repository;

import com.it.arktech.model.Member;
import com.it.arktech.repository.MemberRepository;

@Repository
public class JdbcMemberRepositoryImpl implements MemberRepository {
	
	@Autowired
	SqlMapClientTemplate sqlMapClientTemplate;
	
	public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
		this.sqlMapClientTemplate = sqlMapClientTemplate;
	}
	public List<Member> findAllMember() throws SQLException {
		try{
			@SuppressWarnings("unchecked")
			List<Member> memberList = (List<Member>)sqlMapClientTemplate.queryForList("memberSql.findAllMember");
			return memberList;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	public Member findMemberById(int id) throws SQLException {
		try{
			Member findMember = (Member) sqlMapClientTemplate.queryForObject("memberSql.findMemberById", id);
			return findMember;
			
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	public void insertMember(Member member) throws SQLException {
		sqlMapClientTemplate.insert("memberSql.insertMember", member);		
	}
	public void updateMemberById(int id) throws SQLException {
		sqlMapClientTemplate.update("memberSql.updateMember", id);		
	}
	public void deleteMemberById(int id) throws SQLException {
		sqlMapClientTemplate.delete("memberSql.deleteMemberById",id);		
	}
	
}
